package com.gollum.web.controller.system;

import com.alibaba.fastjson2.JSONObject;
import com.gollum.common.domain.response.RestResponse;
import com.gollum.common.web.controller.BaseController;
import com.gollum.system.domain.request.SysDictDataRequest;
import com.gollum.system.service.SysDictDataService;
import com.gollum.system.service.SysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 字典controller
 *
 * @author Herther
 * @createTime 2022年09月17日 22:45:00
 * @since 1.0.0
 */
@Api(tags = "系统管理-数据字典")
@RestController
@RequestMapping("/dict")
public class SysDictController extends BaseController {


    @Autowired
    protected SysDictTypeService sysDictTypeService;

    @Autowired
    protected SysDictDataService sysDictDataService;

    @PostMapping("/listType")
    @ApiOperation(value = "查询字典类型")
    public RestResponse listType() {
        return RestResponse.success(sysDictTypeService.list());
    }


    @PostMapping("/list")
    @ApiOperation(value = "根据字典")
    public RestResponse listPage(@RequestBody JSONObject jsonObject) {
        buildPageQuery(jsonObject);
        SysDictDataRequest params = this.toJavaObjectParams(SysDictDataRequest.class, jsonObject);
        //if (Objects.isNull(params.getDictTypeId())){
        //    return RestResponse.fail("请选择字典类型");
        //}
        return RestResponse.success(sysDictDataService.listPage(params));
    }


    @GetMapping("/get/{id}")
    @ApiOperation(value="根据ID查询字典详情")
    public RestResponse getDetail(@PathVariable("id") Long id){
        return RestResponse.success(sysDictDataService.getDetailById(id));
    }




}
